package com.distributedDataBase.mapper;

import com.distributedDataBase.pojo.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper {
    @Select("select * from tbl_cart")
    List<Cart> findAll();

    @Select("select * from tbl_cart where user_id = #{value}")
    List<Cart> findByUserId(int userId);

    @Delete("delete from tbl_cart where id=#{id} and user_id=#{userId}")
    int delCart(@Param("id") Integer id, @Param("userId") Integer userId);

    @Update("update tbl_cart set total = #{total} where id = #{id} and user_id = #{userId}")
    int altTotal(@Param("id") Integer id, @Param("userId") Integer userId, @Param("total") Integer total);

    @Insert("insert into tbl_cart (product_id, name, price, img_url, remark, total, create_date, user_id) values (#{productId}, #{name}, #{price}, #{imgUrl}, #{remark}, #{total}, #{createDate}, #{userId})")
    int addCart(Cart cart);

    @Select("select * from tbl_cart where user_id = #{uid} and product_id = #{pid}")
    Cart getByUidAndPid(@Param("uid") Integer uid, @Param("pid") Integer pid);
}
